/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { Modal, Row, Col } from 'antd';
import List from './List';

const Index: React.FC<{
  data: any;
  isOpened: boolean | undefined;
  onOk: Function;
  onCancel: Function;
  queryConfig: any;
  brands: { value: string; label: string; order_type: string }[] | undefined;
}> = (props) => {
  const { data, isOpened, onOk, onCancel, queryConfig, brands } = props;
  const { refund_amount = 0, refund_time = 0 } = data;
  const orderSource = [
    {
      dataIndex: 'order_id',
      title: '订单号',
    },
    {
      dataIndex: 'third_party_orderid',
      title: '客户订单号',
    },

    {
      dataIndex: 'channel',
      title: '订单渠道',
      width: 200,
      renderText: (_: any, value: any) => {
        return queryConfig ? queryConfig.channel?.[value] : '';
      },
    },
    {
      dataIndex: 'order_type',
      title: '订单类型',
      renderText(_: any, value: string) {
        return brands ? brands.filter((item) => item.order_type == value)[0]?.label : '';
      },
    },
    {
      dataIndex: 'order_status',
      title: '订单状态',
      renderText(_: any, value: string) {
        return queryConfig ? queryConfig.order_status?.[value] : '';
      },
    },
    {
      dataIndex: 'package_note',
      title: '订单备注',
    },
    { dataIndex: 'cancel_reason', title: '订单取消原因', width: 140 },

    { dataIndex: 'order_created_at', title: '下单时间' },
    { dataIndex: 'collect_shop_name', title: '接单网点' },
    {
      title: '预计接单时间',
      width: 210,
      renderText(d: any) {
        const { receive_end_time } = d;
        if (receive_end_time) {
          return `${receive_end_time}`;
        }
        return '';
      },
    },
    { dataIndex: 'receive_time', title: '实际接单时间', width: 170 },
    {
      dataIndex: 'receive_status',
      title: '接单状态',
      width: 150,
      renderText(_: any, value: string) {
        return queryConfig ? queryConfig.receive_status?.[value] : '';
      },
    },
    {
      dataIndex: 'collect_courier_name',
      title: '接单快递员',
      width: 110,
    },
    { dataIndex: 'real_collect_courier_mobile', title: '快递员手机号' },
  ];
  const shipperOrShippingSource = [
    { dataIndex: 'waybill_no', title: '运单号' },

    {
      title: '预计揽件时间',
      width: 210,
      renderText(d: any) {
        const { reserve_start_time, reserve_end_time } = d;
        if (reserve_start_time && reserve_end_time) {
          return `${reserve_start_time}~${reserve_end_time}`;
        } else if (reserve_end_time) {
          return reserve_end_time;
        }
        return '';
      },
    },
    {
      dataIndex: 'collect_date',
      title: '实际揽件时间',
      width: 100,
    },
    {
      dataIndex: 'collect_status',
      title: '揽件状态',
      width: 100,
      renderText(_: any, value: string) {
        return queryConfig ? queryConfig.collect_status?.[value] : '';
      },
    },

    {
      dataIndex: 'real_collect_courier_name',
      title: '揽件业务员',
      width: 130,
    },
    {
      dataIndex: 'real_collect_courier_mobile',
      title: '揽件业务员电话',
      width: 130,
    },
  ];
  const collectSource = [
    { dataIndex: 'shipper_uid', title: '用户ID' },
    {
      dataIndex: 'shipper_name',
      title: '寄件人信息',
      renderText: (d: any) => {
        return (
          <>
            <p>
              {d.shipper_name} {d.shipper_mobile}
            </p>
            <p>{d.shipper_province + d.shipper_city + d.shipper_address}</p>
          </>
        );
      },
    },
    {
      title: '收件人信息',
      renderText: function (d: any) {
        return (
          <div>
            <p>
              {d.shipping_name} {d.shipping_mobile}
            </p>
            <p>
              {d.shipping_province}-{d.shipping_city}-{d.shipping_district}-{d.shipping_address}
            </p>
          </div>
        );
      },
    },
  ];
  const packageorpaySource = [
    { dataIndex: 'package_info', title: '物品类型', width: 90 },

    { dataIndex: 'product_name', title: '产品类型', width: 90 },

    { dataIndex: 'real_warrant_price', title: '保价金额', width: 90 },

    { dataIndex: 'package_weight', title: '物品重量', width: 90 },

    {
      dataIndex: 'settlement_volume',
      title: '结算体积',
      renderText(_: any, value: string) {
        return value ? `${value}立方厘米` : '';
      },
    },

    { dataIndex: 'welfare_type', title: '福利类型', width: 90 },
    {
      dataIndex: 'welfare_money',
      title: '福利金额',
    },
    {
      dataIndex: 'help_status',
      title: '助力状态',
      renderText(_: any, value: string) {
        return queryConfig ? queryConfig?.help_status[value] : '';
      },
    },

    { dataIndex: 'sign_date', title: '签收时间' },

    { dataIndex: 'charging_weight', title: '结算重量' },
    { dataIndex: 'sign_status_desc', title: '签收状态' },

    { dataIndex: 'pay_price', title: '结算金额', width: 90 },
    { dataIndex: 'freight_price', title: '运费', width: 90 },
    { dataIndex: 'packing_money', title: '包装费', width: 90 },
    { dataIndex: 'other_money', title: '其他费用', width: 90 },
    {
      dataIndex: 'pay_status',
      title: '扣款状态',
      width: 90,
      renderText(_: any, value: string) {
        return queryConfig ? queryConfig.pay_status?.[value] : '';
      },
    },

    { dataIndex: 'pay_date', title: '扣款时间', width: 190 },
    {
      dataIndex: 'pay_type',
      title: '扣款方式',
      width: 90,
      renderText(_: any, value: string) {
        return queryConfig ? queryConfig.pay_type?.[value] : '';
      },
    },

    { dataIndex: 'order_number', title: '支付商户号', width: 100 },
    { dataIndex: 'trade_number', title: '交易流水号', width: 100 },
    { dataIndex: 'refund_amount', title: '退款金额', hide: !refund_amount, width: 100 },
    { dataIndex: 'refund_time', title: '退款时间', hide: !refund_time, width: 100 },
  ];
  const handleCancel = () => {
    onCancel();
  };
  const handleOk = () => {
    onOk();
  };
  return (
    <Modal
      title='详情信息'
      visible={isOpened}
      width={1000}
      cancelButtonProps={{
        style: { display: 'none' },
      }}
      onCancel={handleCancel}
      onOk={handleOk}
    >
      <Row justify='space-between' style={{ width: '100%' }}>
        <Col xs={12} md={12} lg={6} xl={6} xxl={6}>
          <List data={data} options={orderSource} title='订单信息' />
        </Col>
        <Col xs={24} md={24} lg={12} xl={12} xxl={12}>
          <List data={data} options={shipperOrShippingSource} title='运单信息' />
          <List data={data} options={collectSource} title='收寄件信息' />
        </Col>
        <Col xs={12} md={12} lg={6} xl={6} xxl={6}>
          <List data={data} options={packageorpaySource} title='物品及支付信息' />
        </Col>
      </Row>
    </Modal>
  );
};

export default Index;
